<template>
		<ContentWrap>
            <template #header>
                <el-space wrap>
                    <mdp-hi-query :column-configs="columnConfigs" v-model="hiQueryParams" @change="onHiQueryParamsChange"/>
                    <el-button icon="zoom-out" @click="searchReset()" title="重置查询条件"/> 
                    <el-button icon="download" @click="export2Excel()" title="导出当前结果" />
                    <mdp-table-configs :column-configs="columnConfigs" v-model="checkedColumns"/>
                </el-space> 
            </template>
            <el-space wrap>
			<el-input v-model="filters.id" style="width: 20%;" placeholder="数据集编号" clearable title="支持>、<、 >=、<=、!=、*字符*、$IS NULL、$IN 1,2,3、$between 1,5等操作符"/>
 			<el-button v-loading="load.list" :disabled="load.list==true" @click="searchTableDatas()" icon="search" type="primary">查询</el-button>
			<span style="float:right;" v-if="currOpType=='mng'">
                <el-button :disabled="disBtn('addBtn') || !checkBtnQx('addBtn',menuDefId) " type="primary" @click="openForm({parentOpType:currOpType,subOpType:'add',formData:addForm,title:'新增'})" icon="plus"/>
                <el-button :disabled="disBtn('delBtn') || !checkBtnQx('delBtn',menuDefId) || this.sels.length===0 || load.del==true" type="danger" v-loading="load.del" @click="batchDel" icon="delete"/>
            </span>
            <span style="float:right;" v-else-if="currOpType=='select' &&  this.multiple==true">
                <el-button :disabled="disBtn('selectBtn') || this.sels.length===0" type="primary" @click="selectListConfirm" icon="check"/>
            </span>
            </el-space>
		</ContentWrap>
			<!--列表 DataSet 数据集-->
			<el-table :ref="refId+'Table'" v-adaptive :data="tableDatas" @sort-change="sortChange" highlight-current-row v-loading="load.list" @selection-change="selsChange" @row-click="rowClick" style="width: 100%;">
				<el-table-column  type="selection" width="55" show-overflow-tooltip fixed="left" v-if="currOpType=='mng' || this.multiple==true"/>
				<el-table-column sortable type="index" width="55" show-overflow-tooltip  fixed="left"/>
				<el-table-column prop="id" label="编号" min-width="120" show-overflow-tooltip  fixed="left" col-type="String" v-if="showCol('id')"/>
                
				<el-table-column prop="title"  label="标题" min-width="120" show-overflow-tooltip col-type="String" v-if="showCol('title')">
				    <template #default="scope">
                            <mdp-input show-style="tag" v-model="scope.row.title" :maxlength="255" @change="editSomeFields(scope.row,'title',$event)" :disabled="disField"/>
				    </template>
				</el-table-column>
				<el-table-column prop="dataModel"  label="数据模型" min-width="120" show-overflow-tooltip col-type="String" v-if="showCol('dataModel')">
				    <template #default="scope">
                            <mdp-input show-style="tag" v-model="scope.row.dataModel" :maxlength="50" @change="editSomeFields(scope.row,'dataModel',$event)" :disabled="disField"/>
				    </template>
				</el-table-column>
				<el-table-column prop="dsSql"  label="sql" min-width="120" show-overflow-tooltip col-type="String" v-if="showCol('dsSql')">
				    <template #default="scope">
                            <mdp-input show-style="tag" v-model="scope.row.dsSql" :maxlength="65535" @change="editSomeFields(scope.row,'dsSql',$event)" :disabled="true||disField"/>
				    </template>
				</el-table-column>
				<el-table-column prop="dataSource"  label="数据源" min-width="120" show-overflow-tooltip col-type="String" v-if="showCol('dataSource')">
				    <template #default="scope">
                            <mdp-input show-style="tag" v-model="scope.row.dataSource" :maxlength="50" @change="editSomeFields(scope.row,'dataSource',$event)" :disabled="disField"/>
				    </template>
				</el-table-column>
				<el-table-column prop="cuserid"  label="创建者" min-width="120" show-overflow-tooltip col-type="String" v-if="showCol('cuserid')">
				    <template #default="scope">
                            <mdp-input show-style="tag" v-model="scope.row.cuserid" :maxlength="50" @change="editSomeFields(scope.row,'cuserid',$event)" :disabled="disField"/>
				    </template>
				</el-table-column>
				<el-table-column prop="ctime"  label="创建时间" min-width="120" show-overflow-tooltip col-type="Date" v-if="showCol('ctime')">
				    <template #default="scope">
                            <mdp-date type="date" placeholder="选择日期" show-style="tag" v-model="scope.row.ctime" @change="editSomeFields(scope.row,'ctime',$event)"  value-format="YYYY-MM-DD HH:mm:ss" format="YYYY-MM-DD" :disabled="disField"/>
				    </template>
				</el-table-column>
				<el-table-column prop="cbranchId"  label="创建者机构号" min-width="120" show-overflow-tooltip col-type="String" v-if="showCol('cbranchId')">
				    <template #default="scope">
                            <mdp-input show-style="tag" v-model="scope.row.cbranchId" :maxlength="50" @change="editSomeFields(scope.row,'cbranchId',$event)" :disabled="disField"/>
				    </template>
				</el-table-column>
				<el-table-column prop="euserid"  label="最后修改人" min-width="120" show-overflow-tooltip col-type="String" v-if="showCol('euserid')">
				    <template #default="scope">
                            <mdp-input show-style="tag" v-model="scope.row.euserid" :maxlength="50" @change="editSomeFields(scope.row,'euserid',$event)" :disabled="disField"/>
				    </template>
				</el-table-column>
				<el-table-column prop="etime"  label="最后修改时间" min-width="120" show-overflow-tooltip col-type="Date" v-if="showCol('etime')">
				    <template #default="scope">
                            <mdp-date type="date" placeholder="选择日期" show-style="tag" v-model="scope.row.etime" @change="editSomeFields(scope.row,'etime',$event)"  value-format="YYYY-MM-DD HH:mm:ss" format="YYYY-MM-DD" :disabled="disField"/>
				    </template>
				</el-table-column>
				<el-table-column prop="idTitleLinks"  label="字段关系对照" min-width="120" show-overflow-tooltip col-type="String" v-if="showCol('idTitleLinks')">
				    <template #default="scope">
                            <mdp-input show-style="tag" v-model="scope.row.idTitleLinks" :maxlength="255" @change="editSomeFields(scope.row,'idTitleLinks',$event)" :disabled="disField"/>
				    </template>
				</el-table-column>
				<el-table-column label="操作" :width="currOpType=='mng'?280:200" fixed="right"> 
				    <template #default="scope" v-if="currOpType=='mng'"  >
                        <el-button   type="primary" @click="openForm({parentOpType:currOpType,subOpType:'data',formData:scope.row})" icon="view" title="数据"/>

				        <el-button :disabled="disBtn('editBtn') || !checkBtnQx('editBtn',menuDefId) " type="primary" @click="openForm({parentOpType:currOpType,subOpType:'edit',formData:scope.row,title:'修改'})" icon="edit" title="修改一条数据"/>
				        <el-button :disabled="disBtn('addBtn') || !checkBtnQx('addBtn',menuDefId) " type="success" @click="copy(scope.row)" icon="document-copy" title="拷贝并新增一条除了主键不一样其它都一样的数据"/>
				        <el-button :disabled="disBtn('delBtn') || !checkBtnQx('delBtn',menuDefId) " type="danger" @click="handleDel(scope.row,scope.$index)" icon="delete"  title="删除一条数据"/>
				    </template>

				    <template #default="scope" v-else-if="currOpType=='list'" >
				        <el-button   type="primary" @click="openForm({parentOpType:currOpType,subOpType:'detail',formData:scope.row})" icon="view"/>
 				    </template>

				    <template #default="scope" v-else-if="currOpType=='select' && this.multiple!=true" >
				        <el-button   type="primary" @click="selectConfirm(scope.row)" icon="check"/>
 				    </template>
				</el-table-column>
			</el-table> 
			<el-pagination
				:layout="pageLayout"
				@current-change="handleCurrentChange"
				@size-change="handleSizeChange"
				:page-sizes="[10,20, 50, 100, 500]"
				:current-page="pageInfo.pageNum"
				:page-size="pageInfo.pageSize"
				:total="pageInfo.total" 
			/> 
			<!--新增修改明细 DataSet 数据集界面-->
            <mdp-dialog :ref="refId+'FormDialog'">
                <template v-slot="{visible,data}">
                     <data-set-form :ref="refId+'Form'" :visible="visible" :parent-op-type="currOpType" :sub-op-type="data.subOpType" :form-data="data.formData" @close="onFormClose" @submit="afterFormSubmit" @fields-change="afterEditSomeFields"/>
                </template>
            </mdp-dialog> 
</template>

<script>

import { MdpTableMixin } from '@/components/mdp-ui/mixin/MdpTableMixin.js';
import * as DataSetApi from '@/api/mdp/dm/dataSet';
import  DataSetForm from './Form.vue';//新增修改明细界面
import { mapState } from 'pinia'
import { useUserStore } from '@/store/modules/user'

export default {
    name:'dataSetMng',
    mixins:[MdpTableMixin],
    components: {
        DataSetForm,
    },
    computed: {
        ...mapState(useUserStore,['userInfo'])
    },
    watch:{
    },
    data() {
        return {
            menuDefId:'',//menu_def.id 菜单表菜单编号，用于按钮权限判断
            menuDefName:'数据集',//menu_def.name 功能名称，用于导出excel等文件名
            refId:'dataSet',//引用编号，<table :ref="refId+'Table'"> <form :ref="refId+'Form'">
            pkNames:["id"],//表格主键的java属性名称，驼峰命名，默认为id,支持多主键
            
            filters:{//查询参数

            },
            defaultFilters:{//默认查询参数,第一次打开界面的时候用到，恢复默认值的时候用到

            },

            defaultCheckColumnNum:8,//默认展示的表格列数，前8列

            editable:false,//是否可编辑模式

            //增删改查(含批量)接口
            apis:{
                list: DataSetApi.listDataSet,
                add: DataSetApi.addDataSet,
                del: DataSetApi.delDataSet,
                edit: DataSetApi.editDataSet,
                editSomeFields: DataSetApi.editSomeFieldsDataSet,
                batchAdd: DataSetApi.batchAddDataSet,
                batchDel: DataSetApi.batchDelDataSet,
                batchEdit: DataSetApi.batchEditDataSet,
            }
        }
    },
    methods: {
         //页面初始化需要配置的特殊逻辑写这里
          initCurrData(){
             this.searchTableDatas();
          },

          /**
           * 检查参数是否满足调用后台接口的条件
           *
           * @param params 提交给后台的参数池,map类型
           * @returns true / false
           */
          preQueryParamCheck(params){
              return true;
          },

          //页面数据加载完后需要对数据进行加工处理的
          afterList(tableDatas,isOk,apiName){

          },

          /**
           * 对修改的字段进行判断，返回false ,将取消更新数据库
           * @param {*} row 当前选中的行
           * @param {*} fieldName 修改的字段名
           * @param {*} $event 修改后的值
           * @param {*} params 将要提交服务器的参数
           * @returns true/false 返回false ,将取消更新数据库
           */
          editSomeFieldsCheck(row,fieldName,$event,params){
              if(this.currOpType=='add'||this.currOpType=='detail'){
                  return false;
              }
              params[fieldName]=$event
              return true;
          },
          openForm(res){
            let {formData,subOpType}=res
            
            if(subOpType=='edit'){
                this.$router.push({path:`/mdp/dm/data/set/edit/${formData.id}`})
            }else if(subOpType=='add'){
                this.$router.push({path:`/mdp/dm/data/set/create`})
            }else if(subOpType=='data'){
                this.$router.push({path:`/mdp/dm/data/set/list/${formData.id}`})
            }
          }
    },
    mounted() {

    }
}

</script>

<style scoped>
</style>